package com.doit.hbase.client;

import com.doit.hbase.utils.HbaseUtils;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.Table;

import java.io.IOException;
import java.util.Arrays;
import java.util.List;

/**
 * @DATE 2021/12/13/14:48
 * @Author MDK
 * @Version 2021.2.2
 *  get对象确定的是表中的一行数据
 *  直接调用get()方法  获取的是一行数据
 *  通过get.addColumn 和  get.addFamily 获取指定列或列族数据
 **/
public class C05_Get {
    public static void main(String[] args) throws Exception {
        Connection connection = HbaseUtils.getConnection();
        Table table = HbaseUtils.getTable("tb_teacher", connection);
        getMoreRowTable(table);
        table.close();
        connection.close();
    }

    private static void getMoreRowTable(Table table) throws IOException {
        //创建多个get对象
        Get get1 = new Get("rk001".getBytes());
        get1.addColumn("cf".getBytes(), "name".getBytes());
        Get get2 = new Get("rk002".getBytes());

        List<Get> list = Arrays.asList(get1, get2);
        Result[] results = table.get(list);
        for (Result result : results) {
            HbaseUtils.show(result);
        }
    }

    private static void getOneRowData(Table table) throws IOException {
        //获取的是行的所有数据
        Get get = new Get("rk001".getBytes());
        Result result = table.get(get);
//        get.addColumn();
//        get.addFamily();

        HbaseUtils.show(result);
    }
}
